import logging
import logging.handlers

handler = None
visited_loggers = set()

def func001(name, filename):
    global handler
    
    formatter = logging.Formatter(
        fmt="%(asctime)s | %(levelname)s | %(name)s | %(message)s | %(filename)s[line:%(lineno)d]",
        datefmt="%Y-%m-%d %H:%M:%S",
    )
    
    if not logging.getLogger().handlers:
        logging.basicConfig(level=logging.DEBUG)
    logging.getLogger().handlers[0].setFormatter(formatter)
            
    l1 = logging.getLogger('stdout')
    l2 = logging.getLogger('stderr')
    l3 = logging.getLogger(name)
    
    handler = logging.handlers.TimedRotatingFileHandler(
        filename, when='M', utc=True, encoding="utf-8"
    )
    handler.setFormatter(formatter)
    
    for logger in (l1, l2, l3, ):
        if logger in visited_loggers:
            print(f'**** {logger} in visited_loggers')
            continue
        visited_loggers.add(logger)
        logger.addHandler(handler)
        